package com.crr.mall.ware.controller;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

//import org.apache.shiro.authz.annotation.RequiresPermissions;
import cn.hutool.core.bean.BeanUtil;
import com.crr.mall.common.bean.ResultBean;
import com.crr.mall.common.utils.BaseController;
import com.crr.mall.ware.query.PurchaseQuery;
import com.crr.mall.ware.vo.MergeVO;
import com.crr.mall.ware.vo.PurchaseDoneVO;
import org.aspectj.weaver.ast.Var;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.crr.mall.ware.entity.PurchaseEntity;
import com.crr.mall.ware.service.PurchaseService;
import com.crr.mall.common.utils.PageUtils;
import com.crr.mall.common.utils.R;


/**
 * 采购信息
 *
 * @author chenrenren
 * @email chenrenren@gmail.com
 * @date 2024-11-22 20:37:24
 */
@RestController
@RequestMapping("ware/purchase")
public class PurchaseController extends BaseController {
    @Autowired
    private PurchaseService purchaseService;

    /**
     * 合并采购详情
     *
     * @param mergeVO
     * @return
     */
    @PostMapping("/merge")
    public ResultBean merge(@RequestBody MergeVO mergeVO) {
        int i = purchaseService.mergePurchase(mergeVO);
        return updateResult(i);
    }

    /**
     * 领取采购单
     * @param ids
     * @return
     */
    @PostMapping("/recive")
    public ResultBean recive(@RequestBody List<Long> ids) {
        int i = purchaseService.recivePurchase(ids);
        return success("成功领取采购单",i);
    }
    @PostMapping("/done")
    public ResultBean finishBuy(@RequestBody PurchaseDoneVO purchaseDoneVO){
       int i= purchaseService.purchaseFinish(purchaseDoneVO);
        return success("完成采购",i);

    }

    @PostMapping("/listinfo")
    // @RequiresPermissions("ware:purchase:list")
    public ResultBean list(@RequestBody PurchaseQuery purchaseQuery) {
        PageUtils page = purchaseService.queryByCondition(BeanUtil.beanToMap(purchaseQuery));
        return success("采买列表", page);
    }


    /**
     * 列表
     */
    @RequestMapping("/list")
    // @RequiresPermissions("ware:purchase:list")
    public R list(@RequestParam Map<String, Object> params) {
        PageUtils page = purchaseService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    // @RequiresPermissions("ware:purchase:info")
    public R info(@PathVariable("id") Long id) {
        PurchaseEntity purchase = purchaseService.getById(id);

        return R.ok().put("purchase", purchase);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    // @RequiresPermissions("ware:purchase:save")
    public R save(@RequestBody PurchaseEntity purchase) {
        purchaseService.save(purchase);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    // @RequiresPermissions("ware:purchase:update")
    public R update(@RequestBody PurchaseEntity purchase) {
        purchaseService.updateById(purchase);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    // @RequiresPermissions("ware:purchase:delete")
    public R delete(@RequestBody Long[] ids) {
        purchaseService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

}
